# -*- coding: UTF-8 -*-
import datetime
from typing import Optional

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, sessionmaker

from sqlalchemy import DateTime, String, Text, text, Date
from sqlalchemy.dialects.mysql import INTEGER, TINYINT


class Base(DeclarativeBase):
    pass



class BasMofDiv(Base):
    __tablename__ = 'bas_mof_div'
    __table_args__ = {'comment': '财政区划表'}

    mof_div_id: Mapped[str] = mapped_column(String(38, 'utf8_bin'), primary_key=True, server_default=text("''"), comment='主键')
    mof_div_code: Mapped[str] = mapped_column(String(9, 'utf8_bin'), server_default=text("''"), comment='区划编码')
    mof_div_name: Mapped[str] = mapped_column(String(60, 'utf8_bin'), server_default=text("''"), comment='区划名称')
    parent_id: Mapped[str] = mapped_column(String(38, 'utf8_bin'), server_default=text("''"), comment='父级信息项主键')
    level_no: Mapped[int] = mapped_column(INTEGER(11), server_default=text("'0'"), comment='当前信息项级次')
    is_leaf: Mapped[int] = mapped_column(INTEGER(11), server_default=text("'0'"), comment='当前信息项是否为末级节点')
    start_date: Mapped[datetime.date] = mapped_column(Date, server_default=text("'1970-01-01'"), comment='启用日期yyyymmdd')
    end_date: Mapped[datetime.date] = mapped_column(Date, server_default=text("'1970-01-01'"), comment='结束日期yyyymmdd')
    is_enabled: Mapped[int] = mapped_column(INTEGER(11), server_default=text("'1'"), comment='是否启用')
    update_time: Mapped[datetime.datetime] = mapped_column(DateTime, server_default=text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), comment='维护本条信息项的更新时间')
    is_deleted: Mapped[int] = mapped_column(TINYINT(4), server_default=text("'2'"), comment='逻辑删除')
    adm_div_code: Mapped[str] = mapped_column(String(9, 'utf8_bin'), server_default=text("''"), comment='无对应的行政区划代码的时候为空')
    mof_div_type: Mapped[int] = mapped_column(INTEGER(11), comment='1：中央 2：省 3：计划单列市 4：市 5：区（县）级 51：省直管县 52：其他县 6：乡级 ')
    is_admdiv: Mapped[int] = mapped_column(INTEGER(11), comment='当区划是类似开发区等不存在的新政区划')
    parent_adm_div_code: Mapped[str] = mapped_column(String(9, 'utf8_bin'), server_default=text("''"), comment='为中央的时候为空')
    biz_key: Mapped[str] = mapped_column(String(38, 'utf8_bin'), server_default=text("''"), comment='业务标识id')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, server_default=text('CURRENT_TIMESTAMP'), comment='创建时间')
    is_standard: Mapped[str] = mapped_column(String(1, 'utf8_bin'), server_default=text("''"), comment='0标准代码集 1扩展代码集')
    fiscal_year: Mapped[str] = mapped_column(String(4, 'utf8_bin'), comment='业务年度')
    mof_div_name_alias: Mapped[Optional[str]] = mapped_column(String(100, 'utf8_bin'), server_default=text("''"), comment='区划别名')
    parent_adm_div_name: Mapped[Optional[str]] = mapped_column(String(60, 'utf8_bin'), server_default=text("''"), comment='上级区划名称')
    regional_type: Mapped[Optional[int]] = mapped_column(TINYINT(4), comment='区划类型,1:区级区划,2:县级区划')


class BgtAccountSql(Base):
    __tablename__ = 'bgt_account_sql'
    __table_args__ = {'comment': '补记账配置表'}

    busi_type_code: Mapped[str] = mapped_column(String(50, 'utf8_bin'), primary_key=True, server_default=text("''"), comment='业务类型')
    account_sql: Mapped[Optional[str]] = mapped_column(Text(collation='utf8_bin'), comment='业务数据sql')
